using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using SideShow.Events;
using System.Net.Sockets;
using Serialization;
using SideShow.Channel.Messages;

namespace SideShow.Channel
{
    public class PocketPCServerChannel : PocketPCChannelBase, IServerChannel
    {
        private IClientChannel _callback;

        public PocketPCServerChannel(TcpClient client, IClientChannel callback) : base(client)
        {
            _callback = callback;
        }

        protected override void OnDataReceived(Message msg)
        {
            if (msg is PostEventMessage)
            {
                _callback.PostEvent(((PostEventMessage) msg).Event);
            }
        }

        #region IServerChannel Members

        public void AddApplication(SideShowApplication app)
        {
            Send(new AddApplicationMessage(app));
        }

        public void AddContent(Guid applicationId, Guid sideShowEndpointId, SideShow.Contents.Content newContent)
        {
            Send(new AddContentMessage(applicationId, sideShowEndpointId, newContent));
        }

        public void RemoveApplication(Guid appId)
        {
            Send(new RemoveApplicationMessage(appId));
        }

        public void RemoveContent(Guid applicationId, Guid sideShowEndpointId, uint removedContentId)
        {
            Send(new RemoveContentMessage(applicationId, sideShowEndpointId, removedContentId));
        }

        public void Initialize()
        {
            Send(new InitializeMessage());
        }

        public void Deinitialize()
        {
            Send(new DeinitializeMessage());
        }

        

        #endregion
    }
}
